/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.getsoftware.davicalcados.gui.cadastro;

import br.com.getsoftware.davicalcados.bo.ContasReceberBO;
import br.com.getsoftware.davicalcados.bo.EntradaBO;
import br.com.getsoftware.davicalcados.bo.ProdutoBO;
import br.com.getsoftware.davicalcados.bo.ProdutoVendidoBO;
import br.com.getsoftware.davicalcados.bo.VendaBO;
import br.com.getsoftware.davicalcados.entity.ContasReceber;
import br.com.getsoftware.davicalcados.entity.Entrada;
import br.com.getsoftware.davicalcados.entity.Produto;
import br.com.getsoftware.davicalcados.entity.ProdutoVendido;
import br.com.getsoftware.davicalcados.entity.UsuarioLogado;
import br.com.getsoftware.davicalcados.entity.Venda;
import br.com.getsoftware.davicalcados.util.DataAtual;
import br.com.getsoftware.davicalcados.util.LastID;
import java.io.IOException;
import java.sql.SQLException;
import java.text.NumberFormat;
import javax.swing.JOptionPane;

/**
 *
 * @author Junior Oliveira
 */
public class FormaDePagamento extends javax.swing.JDialog {

    /**
     * Creates new form FormaDePagamento
     */
    public FormaDePagamento() {
        initComponents();
        bloqueaCampos();
        campoNaoAlterados();
        jTvalor.setText("" + 500);
        jTvalorVenda.setText("" + 500);
    }

    private CadVendaGUI cadVenda;
    private Venda venda = new Venda();

    public FormaDePagamento(boolean modal, Venda venda, CadVendaGUI cadVenda) {
//        this();
        super(cadVenda, modal);
        initComponents();
        bloqueaCampos();
        campoNaoAlterados();
        this.venda = venda;
        this.cadVenda = cadVenda;

        jTvalor.setText("" + venda.getValorTotal());
        jTvalorVenda.setText("" + venda.getValorTotal());
        atualizaParcela();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jCpagamento = new javax.swing.JComboBox();
        jLabel3 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jTvalor = new javax.swing.JTextField();
        jTentrada = new javax.swing.JTextField();
        jTrecebido = new javax.swing.JTextField();
        jTtroco = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        jTvalorVenda = new javax.swing.JTextField();
        jCparcela = new javax.swing.JComboBox();
        jLabel8 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        jCdescontar = new javax.swing.JCheckBox();
        jLabel4 = new javax.swing.JLabel();
        jCdebito = new javax.swing.JCheckBox();
        jCcredito = new javax.swing.JCheckBox();
        jBcalcTroco = new javax.swing.JButton();
        jBcalcTotal = new javax.swing.JButton();
        jBcancelar = new javax.swing.JButton();
        jBfinalizar = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jBvoltar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Forma de pagamento");
        setResizable(false);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                formWindowClosing(evt);
            }
        });

        jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jLabel1.setText("Forma de pagamento");

        jCpagamento.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jCpagamento.setForeground(new java.awt.Color(204, 0, 0));
        jCpagamento.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "-- FORMA --", "1 - Dinheiro", "2 - Cartão", "3 - Boleto", "4 - Carné" }));
        jCpagamento.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCpagamentoActionPerformed(evt);
            }
        });

        jLabel3.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel3.setText("Total");

        jLabel5.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel5.setText("Entrada");

        jLabel6.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel6.setText("Valor Recebido");

        jLabel7.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel7.setText("Troco");

        jTvalor.setEditable(false);
        jTvalor.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jTvalor.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        jTvalor.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                jTvalorFocusGained(evt);
            }
            public void focusLost(java.awt.event.FocusEvent evt) {
                jTvalorFocusLost(evt);
            }
        });
        jTvalor.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jTvalorKeyReleased(evt);
            }
        });

        jTentrada.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jTentrada.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        jTentrada.setText("0");
        jTentrada.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                jTentradaFocusGained(evt);
            }
            public void focusLost(java.awt.event.FocusEvent evt) {
                jTentradaFocusLost(evt);
            }
        });
        jTentrada.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTentradaActionPerformed(evt);
            }
        });
        jTentrada.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jTentradaKeyPressed(evt);
            }
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jTentradaKeyReleased(evt);
            }
            public void keyTyped(java.awt.event.KeyEvent evt) {
                jTentradaKeyTyped(evt);
            }
        });

        jTrecebido.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jTrecebido.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        jTrecebido.setText("0");
        jTrecebido.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                jTrecebidoFocusGained(evt);
            }
            public void focusLost(java.awt.event.FocusEvent evt) {
                jTrecebidoFocusLost(evt);
            }
        });
        jTrecebido.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jTrecebidoKeyReleased(evt);
            }
            public void keyTyped(java.awt.event.KeyEvent evt) {
                jTrecebidoKeyTyped(evt);
            }
        });

        jTtroco.setEditable(false);
        jTtroco.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jTtroco.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        jTtroco.setText("0");

        jLabel9.setFont(new java.awt.Font("Tahoma", 1, 16)); // NOI18N
        jLabel9.setText("VALOR TOTAL DA VENDA");

        jTvalorVenda.setEditable(false);
        jTvalorVenda.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jTvalorVenda.setHorizontalAlignment(javax.swing.JTextField.RIGHT);

        jCparcela.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jCparcela.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "--Parcelas--", "1x", "2x", "3x", "4x", "5x", "6x", "7x", "8x", "9x", "10x", "11x", "12x" }));
        jCparcela.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCparcelaActionPerformed(evt);
            }
        });

        jLabel8.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel8.setText("Nº de parcelas");

        jLabel10.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jLabel10.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel10.setText("R$");

        jLabel11.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jLabel11.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel11.setText("R$");

        jLabel13.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jLabel13.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel13.setText("R$");

        jLabel14.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jLabel14.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel14.setText("R$");

        jLabel15.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jLabel15.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel15.setText("R$");

        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/getsoftware/davicalcados/icons/Apps-accessories-calculator-icon.png"))); // NOI18N
        jButton1.setText("Calc");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jCdescontar.setSelected(true);
        jCdescontar.setText("Descontar 10% do total");
        jCdescontar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCdescontarActionPerformed(evt);
            }
        });

        jLabel4.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel4.setText("Desconto");

        buttonGroup1.add(jCdebito);
        jCdebito.setText("Débito");
        jCdebito.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCdebitoActionPerformed(evt);
            }
        });

        buttonGroup1.add(jCcredito);
        jCcredito.setSelected(true);
        jCcredito.setText("Crédito");
        jCcredito.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCcreditoActionPerformed(evt);
            }
        });

        jBcalcTroco.setText("Calc troco");
        jBcalcTroco.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBcalcTrocoActionPerformed(evt);
            }
        });

        jBcalcTotal.setText("Calc Total");
        jBcalcTotal.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBcalcTotalActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel11, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jTvalor))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel4)
                            .addComponent(jCdescontar))
                        .addGap(16, 16, 16)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel8)
                                .addGap(0, 0, Short.MAX_VALUE))
                            .addComponent(jCparcela, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel15, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jTvalorVenda, javax.swing.GroupLayout.PREFERRED_SIZE, 241, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jLabel5, javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel9, javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel6, javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel7, javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel13, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel14, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(10, 10, 10)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jTtroco, javax.swing.GroupLayout.PREFERRED_SIZE, 239, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jTrecebido)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jBcalcTroco, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                            .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 203, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGroup(jPanel1Layout.createSequentialGroup()
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jLabel3)
                                .addComponent(jCpagamento, javax.swing.GroupLayout.PREFERRED_SIZE, 175, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGap(6, 6, 6)
                            .addComponent(jCcredito)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                            .addComponent(jCdebito)))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel10, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jTentrada, javax.swing.GroupLayout.PREFERRED_SIZE, 142, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jBcalcTotal, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(6, 6, 6)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jButton1)
                    .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jCcredito)
                        .addComponent(jCdebito))
                    .addComponent(jCpagamento, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel3)
                .addGap(3, 3, 3)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jTvalor, javax.swing.GroupLayout.DEFAULT_SIZE, 32, Short.MAX_VALUE)
                    .addComponent(jLabel11, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel8)
                    .addComponent(jLabel4))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jCparcela, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jCdescontar, javax.swing.GroupLayout.DEFAULT_SIZE, 33, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 6, Short.MAX_VALUE)
                .addComponent(jLabel5)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jTentrada, javax.swing.GroupLayout.DEFAULT_SIZE, 32, Short.MAX_VALUE)
                        .addComponent(jBcalcTotal, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jLabel10, javax.swing.GroupLayout.DEFAULT_SIZE, 33, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel6)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTrecebido, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel13, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jBcalcTroco, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel7)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jTtroco, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel14, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel9)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel15, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTvalorVenda))
                .addContainerGap())
        );

        jPanel1Layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {jTentrada, jTrecebido, jTtroco, jTvalor, jTvalorVenda});

        jBcancelar.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jBcancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/getsoftware/davicalcados/icons/Apps-preferences-web-browser-adblock-icon.png"))); // NOI18N
        jBcancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBcancelarActionPerformed(evt);
            }
        });

        jBfinalizar.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jBfinalizar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/getsoftware/davicalcados/icons/App-Catalog-icon.png"))); // NOI18N
        jBfinalizar.setText("Finalizar venda");
        jBfinalizar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBfinalizarActionPerformed(evt);
            }
        });

        jPanel2.setBackground(new java.awt.Color(204, 0, 0));

        jLabel2.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
        jLabel2.setForeground(new java.awt.Color(255, 255, 255));
        jLabel2.setText("Finalizar venda");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel2)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jBvoltar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/getsoftware/davicalcados/icons/Arrow-previous-icon.png"))); // NOI18N
        jBvoltar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBvoltarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jBfinalizar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jBvoltar, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jBcancelar, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jBfinalizar)
                    .addComponent(jBcancelar)
                    .addComponent(jBvoltar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );

        layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {jBcancelar, jBfinalizar, jBvoltar});

        setSize(new java.awt.Dimension(366, 629));
        setLocationRelativeTo(null);
    }// </editor-fold>//GEN-END:initComponents

    private void jTvalorKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTvalorKeyReleased
        jTvalor.setText(jTvalor.getText().replaceAll("[^0-9 | ^. | ^,]", ""));
    }//GEN-LAST:event_jTvalorKeyReleased

    private void jTvalorFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jTvalorFocusGained
//        jTvalor.setText(TransformMoeda.trasnformMoeda(jTvalor.getText()));
    }//GEN-LAST:event_jTvalorFocusGained

    private void jTvalorFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jTvalorFocusLost
//        jTvalor.setText(TransformMoeda.trasnformMoeda(jTvalor.getText()));
    }//GEN-LAST:event_jTvalorFocusLost

    private void jCpagamentoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCpagamentoActionPerformed
        if (jCpagamento.getSelectedIndex() == 0) {
            bloqueaCampos();
        }
        if (jCpagamento.getSelectedIndex() == 1) {
            vendaDinheiro();
            if (jCdescontar.isSelected()) {
                descontoDezPorcento();
            }
        }
        if (jCpagamento.getSelectedIndex() == 2) {
            vendaCartao();
            if (jCdebito.isSelected()) {
                jCparcela.setEnabled(false);
            }
        }
        if (jCpagamento.getSelectedIndex() == 3) {
            vendaBoleto();
        }
        if (jCpagamento.getSelectedIndex() == 4) {
            vendaCarne();
        }
    }//GEN-LAST:event_jCpagamentoActionPerformed

    public void descontoDezPorcento() {
        double var = Double.valueOf(jTvalor.getText());
        jTvalorVenda.setText("" + ((var - ((Double.valueOf(jTvalor.getText()) / 100) * 10)) - Double.valueOf(jTentrada.getText())));
    }

    private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
        cadVenda.setEnabled(true);
        this.dispose();
    }//GEN-LAST:event_formWindowClosing

    private void jBcancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBcancelarActionPerformed
        cadVenda.setEnabled(true);
        this.dispose();
        cadVenda.getCaixa().setEnabled(true);
        cadVenda.dispose();
    }//GEN-LAST:event_jBcancelarActionPerformed

    private void jBfinalizarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBfinalizarActionPerformed

        try {
            //TEM NÃO SELECIONADO 
            if (jCpagamento.getSelectedIndex() == 0) {
                JOptionPane.showMessageDialog(null, "Deve-se selecioar uma forma de pagamento.", "Atenção!", 2);
                jCpagamento.requestFocus();

            } else if (jCpagamento.getSelectedIndex() == 2 && jCparcela.getSelectedIndex() == 0
                    || jCpagamento.getSelectedIndex() == 3 && jCparcela.getSelectedIndex() == 0
                    || jCpagamento.getSelectedIndex() == 4 && jCparcela.getSelectedIndex() == 0) {

                JOptionPane.showMessageDialog(null, "Deve-se selecioar a quantidade de parcela(s)", "Atenção!", 2);
                jCpagamento.requestFocus();

                // VENDA DINHEIRO
            } else if (jCpagamento.getSelectedIndex() == 1) {

                salvaVendaEProdutosVendidos();
                atualizarEstoque();
                pagamentoDinheiro();
                finalizandoVenda();

                //VENDA CARTÃO
            } else if (jCpagamento.getSelectedIndex() == 2) {

                salvaVendaEProdutosVendidos();
                atualizarEstoque();
                //cartão de débito
                if (jCdebito.isSelected()) {
                    pagamentoCartaoDebito();

                    //cartão de crédito
                } else if (jCcredito.isSelected()) {
                    pagamentoCartaoCredito();
                } else {
                    JOptionPane.showMessageDialog(rootPane, "Erro fatal no sistema!", "Erro", JOptionPane.ERROR_MESSAGE);
                }
                finalizandoVenda();
                //VENDA BOLETO
            } else if (jCpagamento.getSelectedIndex() == 3) {

                salvaVendaEProdutosVendidos();
                atualizarEstoque();
                pagamentoBoleto();
                finalizandoVenda();

                //VENDA CARNE
            } else if (jCpagamento.getSelectedIndex() == 4) {

                salvaVendaEProdutosVendidos();
                atualizarEstoque();
                pagamentoCarne();
                finalizandoVenda();
            }

        } catch (SQLException ex) {
            JOptionPane.showMessageDialog(rootPane, "Não foi possível finalizar a venda!\n\n" + ex.getMessage(), "Erro!", 0);

        }
    }//GEN-LAST:event_jBfinalizarActionPerformed

    /**
     * FINALIZA A VENDA, FECHA AS TELAS DE VENDA E ATUALIZA O CAIXA
     *
     * @throws java.sql.SQLException
     */
    public void finalizandoVenda() throws SQLException {
        JOptionPane.showMessageDialog(rootPane, "Venda realizada com sucesso!.", "Sucesso!!", 1);
        jBcancelarActionPerformed(null);
        cadVenda.getCaixa().dadosTabela();

    }

    /**
     * REALIZA UMA COMPRA A VISTA
     */
    public void pagamentoDinheiro() {
        Entrada entrada = new Entrada();
        entrada.setDataEntrada(DataAtual.dataAtual());
        entrada.setDescricaoEntrada("Venda à vista, valor R$ " + jTvalorVenda.getText());
        entrada.setIdUsuario(UsuarioLogado.usuarioLogado.getIdUsuario());
        entrada.setValorEntrada(Double.valueOf(jTvalorVenda.getText()));
        try {
            EntradaBO.save(entrada);
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(rootPane, "Não foi possível efetuar a venda!\n\n\n" + ex.getMessage(), null, 0);
        }
    }

    public void pagamentoCartaoCredito() {
        Entrada entrada = new Entrada();
        entrada.setDataEntrada(DataAtual.dataAtual());
        entrada.setDescricaoEntrada("Venda no cartão de crédito, em " + jCparcela.getSelectedItem()
                + ", valor R$ " + jTvalorVenda.getText() + ", R$ " + jTentrada.getText() + " de entrada");
        entrada.setIdUsuario(UsuarioLogado.usuarioLogado.getIdUsuario());
        entrada.setValorEntrada(Double.valueOf(jTentrada.getText()));
        try {
            EntradaBO.save(entrada);
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(rootPane, "Não foi possível efetuar a venda!\n\n\n" + ex.getMessage(), null, 0);
        }
    }

    public void pagamentoCartaoDebito() {
        Entrada entrada = new Entrada();
        entrada.setDataEntrada(DataAtual.dataAtual());
        entrada.setDescricaoEntrada("Venda no cartão de débito, Valor R$ " + jTvalorVenda.getText());
        entrada.setIdUsuario(UsuarioLogado.usuarioLogado.getIdUsuario());
        entrada.setValorEntrada(Double.valueOf(0));
        try {
            EntradaBO.save(entrada);
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(rootPane, "Não foi possível efetuar a venda!\n\n\n" + ex.getMessage(), null, 0);
        }
    }

    public void pagamentoBoleto() {

        //CONDIÇÕES PARA GERAR O PARCELAMENTO DA VENDA
        for (int i = 0; i < jCparcela.getSelectedIndex(); i++) {
            ContasReceber contaReceber = new ContasReceber();
            contaReceber.setDataPagamento(DataAtual.dataAtual());
//        contaReceber.setDataQuitado(null);
            contaReceber.setDescricao("Venda no boleto, " + (i + 1) + " de " + jCparcela.getSelectedIndex());
//        contaReceber.setIdContaReceber(Long.MIN_VALUE);
            contaReceber.setStatus(true);
            contaReceber.setIdVenda(LastID.ultimoId("id", "venda"));
            contaReceber.setValor(Double.valueOf(jTvalorVenda.getText()) / jCparcela.getSelectedIndex());
            try {
                ContasReceberBO.save(contaReceber);
            } catch (SQLException ex) {
                JOptionPane.showMessageDialog(rootPane, "Não foi possível efetuar a venda!\n\n\n" + ex.getMessage(), null, 0);
            }
        }
        Entrada entrada = new Entrada();
        entrada.setDataEntrada(DataAtual.dataAtual());
        entrada.setDescricaoEntrada("Venda no boleto, em " + jCparcela.getSelectedIndex() + " vez(es),  Valor R$ " + jTvalorVenda.getText());
        entrada.setIdUsuario(UsuarioLogado.usuarioLogado.getIdUsuario());
        entrada.setValorEntrada(Double.valueOf(jTentrada.getText().replace(",", ".")));

        try {
            EntradaBO.save(entrada);
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(rootPane, "Não foi possível efetuar a venda!\n\n\n" + ex.getMessage(), null, 0);
        }
    }

    public void pagamentoCarne() {

    }

    public void vendaComEntrada() {
        Entrada entrada = new Entrada();
        entrada.setDataEntrada(DataAtual.dataAtual());
        entrada.setDescricaoEntrada("Entrada de parte do pagamento. R$ " + jTentrada.getText() + " de R$ " + jTvalor.getText());
        entrada.setIdUsuario(UsuarioLogado.usuarioLogado.getIdUsuario());
        entrada.setValorEntrada(Double.valueOf(jTentrada.getText()));
        try {
            EntradaBO.save(entrada);
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(rootPane, "Não foi possível efetuar a entrada da venda!\n\n\n" + ex.getMessage(), null, 0);
        }
    }

    public void salvaVendaEProdutosVendidos() {
        try {
            venda.setParcela(jCparcela.getSelectedIndex());
            venda.setValorTotal(Double.valueOf(jTvalorVenda.getText()));
            VendaBO.save(venda);

            for (int i = 0; i < venda.getListaProduto().size(); i++) {
                ProdutoVendido prodVendido = new ProdutoVendido();

                prodVendido.setId_produto("" + venda.getListaProduto().get(i).getIdProduto());
                prodVendido.setId_venda(Long.valueOf("" + LastID.ultimoId("id", "venda")));
                prodVendido.setQuantidade(venda.getListaProduto().get(i).getQuantidade());
                ProdutoVendidoBO.save(prodVendido);

            }

        } catch (Exception ex) {
            JOptionPane.showMessageDialog(rootPane, "Não foi possível salvar a venda!\n\n" + ex.getMessage(), "Erro!", 0);
            ex.printStackTrace();
        }
    }

    public void atualizarEstoque() throws SQLException {

        for (int i = 0; i < venda.getListaProduto().size(); i++) {
            Produto produto = ProdutoBO.getById(venda.getListaProduto().get(i).getIdProduto());
            produto.setQuantidade(produto.getQuantidade() - venda.getListaProduto().get(i).getQuantidade());
            ProdutoBO.update(produto);
        }
    }

    private void jTentradaKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTentradaKeyReleased
//        if (jTentrada.getText() != null || !jTentrada.getText().isEmpty()) {
//            if (Float.valueOf(jTvalor.getText()) > Float.valueOf(jTentrada.getText())) {
//                jTvalorVenda.setText("" + (Float.valueOf(jTvalor.getText()) - Float.valueOf(jTentrada.getText())));
//            } else {
//                jTentrada.setText("0");
//                JOptionPane.showMessageDialog(rootPane, "O valor do entrada é maior que o valor da venda!", "Atenção!", 2);
//
//            }
//        } else {
//            jTentrada.setText("0");
//        }

    }//GEN-LAST:event_jTentradaKeyReleased

    private void jTentradaKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTentradaKeyTyped
//        String caracteres = "0987654321.";
//        if (!caracteres.contains(evt.getKeyChar() + "")) {
//            evt.consume();
//        }
//        if (jTentrada.getText() == null || jTentrada.getText().isEmpty()) {
//            jTentrada.setText("0.00");
//        }
    }//GEN-LAST:event_jTentradaKeyTyped

    private void jTrecebidoKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTrecebidoKeyTyped
//        String caracteres = "0987654321.";
//        if (!caracteres.contains(evt.getKeyChar() + "")) {
//            evt.consume();
//        }
//        if (jTrecebido.getText() == null || jTrecebido.getText().isEmpty()) {
//            jTrecebido.setText("0.00");
//        }
    }//GEN-LAST:event_jTrecebidoKeyTyped

    private void jTrecebidoKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTrecebidoKeyReleased
//        if (jTrecebido.getText() != null || !jTrecebido.getText().isEmpty()) {
////            if (Float.valueOf(jTrecebido.getText()) < Float.valueOf(jTentrada.getText())) {
//            jTtroco.setText("" + (Float.valueOf(jTrecebido.getText()) - Float.valueOf(jTvalorVenda.getText())));
//            } else {
//            jTentrada.setText("0.00");
//            JOptionPane.showMessageDialog(rootPane, "O valor do entrada é maior que o valor da venda!", "Atenção!", 2);

//        }

    }//GEN-LAST:event_jTrecebidoKeyReleased

    private void jTrecebidoFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jTrecebidoFocusLost
//        if (jTecebido.getText() != null || !jTecebido.getText().isEmpty()) {
//            if (Float.valueOf(jTecebido.getText()) >= Float.valueOf(jTvalorVenda.getText())) {
//
//                jTtroco.setText("" + (Float.valueOf(jTecebido.getText()) - Float.valueOf(jTvalorVenda.getText())));
//            } else {
////                jTdesconto.setText("0");
//                JOptionPane.showMessageDialog(rootPane, "O valor recebido é menor que o valor total da compra", "Atenção!", 2);
//                jTdesconto.requestFocus();
//            }
//        }

    }//GEN-LAST:event_jTrecebidoFocusLost

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        try {
            Runtime.getRuntime().exec("cmd.exe /C start calc.exe");
        } catch (IOException ex) {
            JOptionPane.showMessageDialog(rootPane, "Não foi possível abrir a calculadora!", "Erro!", 0);
        }
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jCparcelaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCparcelaActionPerformed
        atualizaParcela();
        if (jCparcela.getSelectedIndex() == 1 && jCdescontar.isSelected()) {
            descontoDezPorcento();
        } else if (Double.valueOf(jTentrada.getText()) > 0) {
            jTvalorVenda.setText("" + (Double.valueOf(jTvalor.getText()) - Double.valueOf(jTentrada.getText())));
        } else {
            jTvalorVenda.setText(jTvalor.getText());
        }
    }//GEN-LAST:event_jCparcelaActionPerformed

    private void jCdescontarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCdescontarActionPerformed
        jCpagamentoActionPerformed(evt);

    }//GEN-LAST:event_jCdescontarActionPerformed

    private void jBvoltarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBvoltarActionPerformed
        formWindowClosing(null);
    }//GEN-LAST:event_jBvoltarActionPerformed

    private void jCdebitoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCdebitoActionPerformed
        jCparcela.setEnabled(false);
        jCparcela.setSelectedIndex(0);

        if (jCdescontar.isSelected()) {
            descontoDezPorcento();
        } else {
            jTvalorVenda.setText(jTvalor.getText());
        }
    }//GEN-LAST:event_jCdebitoActionPerformed

    private void jCcreditoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCcreditoActionPerformed
        jCparcela.setEnabled(true);
        atualizaParcela();
        if (jCparcela.getSelectedIndex() == 1 && jCdescontar.isSelected()) {
            descontoDezPorcento();
        } else {
            jTvalorVenda.setText(jTvalor.getText());
        }
    }//GEN-LAST:event_jCcreditoActionPerformed

    private void jTentradaKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTentradaKeyPressed
//        if (jTentrada.getText().isEmpty() || jTentrada.getText() == null) {
//
//        } else {
//
//        }
    }//GEN-LAST:event_jTentradaKeyPressed

    private void jTentradaFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jTentradaFocusLost
        if (jTentrada.getText().isEmpty() || jTentrada.getText() == null) {
            jTentrada.setText("0");
        }
    }//GEN-LAST:event_jTentradaFocusLost

    private void jTentradaFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jTentradaFocusGained
        jTentrada.selectAll();
    }//GEN-LAST:event_jTentradaFocusGained

    private void jTentradaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTentradaActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTentradaActionPerformed

    private void jTrecebidoFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jTrecebidoFocusGained
        jTrecebido.selectAll();
    }//GEN-LAST:event_jTrecebidoFocusGained

    private void jBcalcTotalActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBcalcTotalActionPerformed
        if(jCpagamento.getSelectedIndex() == 0){
            
        }else{
        }
        
        if(jCparcela.getSelectedIndex() == 0){
            
        }
        
        else{
            
        }
        
        if(jCdescontar.isSelected()){
            
        }
        if(Double.valueOf(jTentrada.getText())>0){
            
        }
        
    }//GEN-LAST:event_jBcalcTotalActionPerformed

    private void jBcalcTrocoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBcalcTrocoActionPerformed
        double valorRecebido = Double.valueOf(jTrecebido.getText());
        double valorTotal = Double.valueOf(jTvalorVenda.getText());

        jTtroco.setText("" + (valorRecebido - valorTotal));
    }//GEN-LAST:event_jBcalcTrocoActionPerformed

    public void atualizaParcela() {
        if (jCparcela.getSelectedIndex() == 0) {
            venda.setParcela(1);
        } else {
            venda.setParcela(Integer.valueOf(jCparcela.getSelectedItem().toString().replace("x", "")));
        }
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Windows".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(FormaDePagamento.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(FormaDePagamento.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(FormaDePagamento.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(FormaDePagamento.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new FormaDePagamento().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JButton jBcalcTotal;
    private javax.swing.JButton jBcalcTroco;
    private javax.swing.JButton jBcancelar;
    private javax.swing.JButton jBfinalizar;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jBvoltar;
    private javax.swing.JCheckBox jCcredito;
    private javax.swing.JCheckBox jCdebito;
    private javax.swing.JCheckBox jCdescontar;
    private javax.swing.JComboBox jCpagamento;
    private javax.swing.JComboBox jCparcela;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JTextField jTentrada;
    private javax.swing.JTextField jTrecebido;
    private javax.swing.JTextField jTtroco;
    private javax.swing.JTextField jTvalor;
    private javax.swing.JTextField jTvalorVenda;
    // End of variables declaration//GEN-END:variables

    private void campoNaoAlterados() {
        jTvalor.setEditable(false);
        jTtroco.setEditable(false);
        jTvalorVenda.setEditable(false);
    }

    private void bloqueaCampos() {
//        jTdesconto.setEnabled(false);
        jTrecebido.setEnabled(false);
        jTentrada.setEnabled(false);
        jCparcela.setEnabled(false);
        jCdebito.setEnabled(false);
        jCcredito.setEnabled(false);
        limpaCampos();
    }

    private void vendaDinheiro() {
//        jTdesconto.setEnabled(true);
        jTrecebido.setEnabled(true);
        jTentrada.setEnabled(false);
        jCparcela.setEnabled(false);
        jCdebito.setEnabled(false);
        jCcredito.setEnabled(false);
        limpaCampos();
    }

    private void vendaCartao() {
//        jTdesconto.setEnabled(false);
        jTrecebido.setEnabled(true);
        jTentrada.setEnabled(true);
        jCparcela.setEnabled(true);

        jCdebito.setEnabled(true);
        jCcredito.setEnabled(true);

        limpaCampos();
    }

    private void vendaBoleto() {
//        jTdesconto.setEnabled(false);
        jTrecebido.setEnabled(true);
        jTentrada.setEnabled(true);
        jCparcela.setEnabled(true);
        jCdebito.setEnabled(false);
        jCcredito.setEnabled(false);
        limpaCampos();
    }

    private void vendaCarne() {
//        jTdesconto.setEnabled(false);
        jTrecebido.setEnabled(true);
        jTentrada.setEnabled(true);
        jCparcela.setEnabled(true);
        jCdebito.setEnabled(false);
        jCcredito.setEnabled(false);
        limpaCampos();
    }

    private void limpaCampos() {
//        jTdesconto.setText(null);
        jTrecebido.setText("0.00");
        jTentrada.setText("0.00");
        jTtroco.setText("0.00");
        jTvalorVenda.setText(jTvalor.getText());
        jCparcela.setSelectedIndex(0);
    }
}
